#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
    int n, k;
    cin >> n >> k;
    ll arr[100010] = {0};
    int i = 0;
    for (i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    ll Min = 2e9;
    for (i = 0; i < n - k + 1; i++)
    {
        int j = 0;
        ll max = -1e9;
        ll min = 1e9;
        for (j = i; j < i + k; j++)
        {
            if (arr[j] > max)
                max = arr[j];
            if (arr[j] < min)
                min = arr[j];
        }
        if (max - min < Min)
            Min = max - min;
    }
    cout << Min ;
}
int main()
{
    solve();
    return 0;
}
